home *** CD-ROM | disk | FTP | other *** search
- ; [03-Feb-84]
- ; Replaced case-sensitive search in PATSEARCH by with one to ignore case
- ; or optionally, require exact case, in matching.
-
- IGNORECASE EQU 1 ; 0 for case-sensitive search
-
- assume cs:utilities
-
- public patsearch
-
- utilities segment para public 'code'
-
- enter macro
- ; Enter a routine and set up bp to point to the argument frame on the stack
- push bp
- mov bp,sp
- add bp,6
- endm
-
- exit macro
- ; Restore stack before "ret n" in a routine entered by the "enter" macro
- pop bp
- endm
-
- assume cs:utilities
- db "<<xnzscasb>>"
- xnzscasb proc near
- ;xnzscasb:
- ;
- ; Begin translated equivalent of REPNZ SCASB
- ;
- push ax ; save ax and
- push bx ; bx during this loop
- mov bx, offset cs:xtable
- xlat byte ptr cs:xtable ; al <- xtable(al) - translated pattern byte
- mov ah,al ; translated pattern byte
-
- loop1:
- mov al,es:byte ptr [di] ; source byte
- xlat byte ptr cs:xtable ; translate source byte in al
- inc di ; point to next byte (like scasb does)
- cmp ah,al ; source = pattern?
- loopne loop1 ; decrement cx and loop while no match
-
- pop bx ; restore bx
- pop ax ; and ax
- ret
- ;
- ; End translated equivalent of REPNZ SCASB
- ;
-
- xtable equ $ ; translation table mapping lower case into upper
- xbyte=0
- rept 97 ; NUL .. "`" --> themselves
- db xbyte
- xbyte=xbyte+1
- endm
- xbyte=65
- rept 26 ; "a".."z" --> "A".."Z"
- db xbyte
- xbyte=xbyte+1
- endm
- xbyte=123
- rept 133 ; "["..0FFH --> themselves
- db xbyte
- xbyte=xbyte+1
- endm
-
-
- xnzscasb endp
-
- assume cs:utilities
- db "<<xzcmpsb>>"
- xzcmpsb proc near
- ;xzcmpsb:
- ;
- ; Begin translated equivalent of REPZ CMPSB
- ;
- push ax ; save ax and
- push bx ; bx during this loop
- mov bx, offset cs:xtable
-
- loop2:
- mov al,ds:byte ptr [si];pattern byte
- xlat byte ptr cs:xtable ; al <- xtable(al) - translated pattern byte
- mov ah,al ; translated pattern byte
- mov al,es:byte ptr [di] ; source byte
- xlat byte ptr cs:xtable ; translate source byte in al
- inc si ; point to next byte (like cmpsb does)
- inc di ; point to next byte (like cmpsb does)
- cmp ah,al ; source = pattern?
- loope loop2 ; decrement cx and loop while match
-
- pop bx ; restore bx
- pop ax ; and ax
- ret
-
- ;
- ; End translated equivalent of REPZ CMPSB
- ;
- xzcmpsb endp
-
- db "<<patsearch>>"
- patsearch proc far ; string search
-
- ; function patsearch( exactmatch: boolean;
- ; const pattern;
- ; searchbuffer: adsmem;
- ; maxcount: word;
- ; ): word;
- ;
- ; After "enter", stack looks like
- ;
- ; 0 - maxcount
- ; 2 - address of searchbuffer
- ; 4 - segment of searchbuffer
- ; 6 - address of pattern
- ; 8 - maximum length of pattern (0..255)
- ; 10 - exactmatch (0 = FALSE, 1 = TRUE)
-
- enter
- mov cx,[bp] ; grab the maximum count
- test cx,cx
- jz pdone
- mov di,[bp+2] ; grab the address of the search buffer
- mov es,[bp+4] ; grab the segment of the search buffer
- mov si,[bp+6] ; grab the address of the pattern
- mov bx,[bp+10] ; grab the exactmatch flag
- cld ; set direction for forward search
- lodsb ; grab the length of the pattern in al
- test al,al ; are there any characters in the pattern?
- jz pdone ; no
-
- mov ah,al ; save length of pattern in al
- dec ah ; one less chars than length(pattern)
- lodsb ; put the first char of pattern in al
-
- ; set up for scan
- ; ax contains the first char of the pattern
- ; bx contains the exactmatch flag
- ; cx contains count of maximum chars to scan for
- ; di contains the starting address for search in sbuffer
- ; si contains the address of the rest of the string
-
- doscan:
- test bx,bx ; exactmatch = 0 (FALSE) or 1 (TRUE)?
- jnz exactscan ; TRUE
- call xnzscasb ; find the first character, ignoring case
- jmp short scandone
-
- exactscan:
- repne scasb ; find the first character, matching case
-
- scandone:
- jne pdone ; character not found so we are done
- push cx ; save remaining count
- push di ; save buffer pointer for next scan
- push si ; save pattern pointer
- test ah,ah
- jz match
- mov cl,ah
- xor ch,ch
- test bx,bx ; exactmatch = 0 (FALSE) or 1 (TRUE)?
- jnz exactcompare ; TRUE
- call xzcmpsb ; compare strings ignoring case
- jmp short comparedone
-
- exactcompare:
- repe cmpsb ; compare strings for exact case match
-
- comparedone:
- je match
- pop si
- pop di
- pop cx
- jmp doscan
-
- match:
- add sp,4 ; pop off si and di
- pop cx
- inc cx
-
- pdone:
- mov ax,[bp] ; chars scanned to find pattern
- sub ax,cx
- exit
- ret 12 ; return discarding arguments
- patsearch endp
-
- utilities ends
- end